var t = require("../../3D336854875DE5CF5B550053BF4D6824.js"), e = (require("../../FFE95507875DE5CF998F3D00DB5D6824.js"), 
require("../../26C7E8E6875DE5CF40A180E17E6D6824.js")), o = (getApp().globalData, 
null), a = null;
const app = getApp()

Page({
    data: {
        test_score:'',
        type: "",
        filePath: "",
        result: [],
        indicatordots: !1,
        swiperHeightRpx: 0,
        descHeight: 0,
        isShare: 0,
        from: "",
        imgUrl: "",
        aiResultStr: ""
    },
    
    
    onLoad: function(t) {

      console.log('hahaha',this.data.test_score)
        console.log("detail:: onload.options", t);
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                var o = t;
                console.log("systeminfo"), console.log(o);
                var a = 750 / o.windowWidth;
                console.log(a);
                var i = o.statusBarHeight;
                console.log("status:" + i);
                var s = o.screenHeight, n = o.windowHeight, l = s - i - 44 - n;
                console.log("tab:" + l);
                var c = (n + l) * a - 600 - 130;
                console.log("swiperHight:" + c);
                var r = c - 80;
                e.setData({
                    swiperHeightRpx: c,
                    descHeight: r
                });
            }
        });
        var o = t.type;
        if (null == o && (o = "plant"), this.setData({
            type: o
        }), null != t.from && this.setData({
            from: t.from
        }), null != t.filePath && "" != t.filePath) if (a = t.filePath, 1 == t.isShare && (t.from = "share", 
        this.setData({
            from: "share"
        })), "share" == t.from || "history" == t.from) {
            var i = t.aiResultStr, s = !1, n = JSON.parse(i);
            n.length > 1 && (s = !0), this.setData({
                filePath: t.filePath,
                imgUrl: t.filePath,
                result: n,
                indicatordots: s
            }), this.setData({
                aiResultStr: i
            });
        } else this.recognize(a, o), this.loadInterstitialAd();
    },
    
    onReady: function() {
        console.log("detail.ready");
        
    },
    onShow: function() {
      
    },
    toHome: function() {
        wx.switchTab({
            url: "/pages/index/index"
        });
    },
    loadInterstitialAd: function() {
      return;
    },
    toHistory: function() {
      console.log("to history"), wx.navigateTo({
          url: "/pages/history/history"
      });
  },
    showInterstitialAd: function() {
        
    },
    recognize: function(o, a) {
        var i = this;
        console.log("detail.recgonize", o, a);
        var s = this;
        t.recognize(o, a).then(function(t) {
          var that = this
          var skin_1 = ''
            if (console.log("res:", t), t) {
                var n = wx.getStorageSync(i) || !1;
                var skinscore = t.skin
                console.log('fan',skinscore)
                skin_1 = t.skin
                console.log('fansi',skin_1)
                i.data.test_score = skin_1
                console.log('fansila',i.data.test_score)
                i.setData({
                  test_score:skin_1
                })
                var l = !1;
                t.aiResult.length > 1 && (l = !0), s.setData({
                    filePath: o,
                    imgUrl: t.imgUrl,
                    result: t.aiResult,
                    indicatordots: l
                });
                var c = JSON.stringify(t.aiResult);
                s.setData({
                    aiResultStr: c
                });
                var r = {
                    type: a,
                    imgUrl: t.imgUrl,
                    aiResultStr: c
                }, g = wx.getStorageSync("aihistory") || [];
                g.unshift(r), wx.setStorageSync("aihistory", g);
            } else console.log("结果有问题"), wx.showToast({
                title: "无法识别"
            });
            
        }).catch(function(t) {
            console.log("errinfo"), console.log(t), i.setData({
                filePath: ""
            }), wx.showModal({
                title: "提示",
                content: t.message,
                showCancel: !1,
                complete: function(t) {
                    t.confirm && wx.navigateBack();
                }
            });
        });
    },
    previewImage: function(t) {
        wx.previewImage({
            urls: this.data.filePath.split(",")
        });
    },
    chooseImageByCamera: function() {
        var e = this.data.type;
        t.chooseImageByCamera(e);
    },
    chooseImageByAlbum: function() {
        var e = this.data.type;
        t.chooseImageByAlbum(e);
    },
    chooseImage: function() {
        var e = this.data.type;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "camera", "album" ],
            success: function(o) {
                console.log("选择照片完成", o);
                var a = o.tempFilePaths[0];
                t.saveAndJump(a, e);
            },
            fail: function(t) {
                console.log("取消了");
            }
        });
    },
    onHide: function() {
        console.log("onhide");
    },
    onUnload: function() {
        console.log("onunload");
    },
  
});